package org.farng.mp3.id3;

import org.farng.mp3.InvalidTagException;
import org.farng.mp3.object.ObjectByteArraySizeTerminated;
import org.farng.mp3.object.ObjectNumberHashMap;
import org.farng.mp3.object.ObjectStringDate;
import org.farng.mp3.object.ObjectStringNullTerminated;

import java.io.IOException;


/**
 * Title: Description: Copyright:    Copyright (c) 2002 Company:
 *
 * @author Eric Farng
 * @version $Revision: 1.3 $
 */
public class FrameBodyCOMR extends AbstractID3v2FrameBody {
    /**
     * Creates a new FrameBodyCOMR object.
     */
    public FrameBodyCOMR() {
        //        this.setObject("Text Encoding", new Byte((byte) 0));
        //        this.setObject("Price String", "");
        //        this.setObject("Valid Until", "");
        //        this.setObject("Contact URL", "");
        //        this.setObject("Recieved As", new Byte((byte) 0));
        //        this.setObject("Name Of Seller", "");
        //        this.setObject("Description", "");
        //        this.setObject("Picture MIME Type", "");
        //        this.setObject("Seller Logo", new byte[0]);
    }

    public FrameBodyCOMR(FrameBodyCOMR body) {
        super(body);
    }

    /**
     * Creates a new FrameBodyCOMR object.
     *
     * @param textEncoding DOCUMENT ME!
     * @param priceString DOCUMENT ME!
     * @param validUntil DOCUMENT ME!
     * @param contactUrl DOCUMENT ME!
     * @param recievedAs DOCUMENT ME!
     * @param nameOfSeller DOCUMENT ME!
     * @param description DOCUMENT ME!
     * @param mimeType DOCUMENT ME!
     * @param sellerLogo DOCUMENT ME!
     */
    public FrameBodyCOMR(byte textEncoding, String priceString, String validUntil, String contactUrl, byte recievedAs, String nameOfSeller, String description, String mimeType, byte[] sellerLogo) {
        this.setObject("Text Encoding", new Byte(textEncoding));
        this.setObject("Price String", priceString);
        this.setObject("Valid Until", validUntil);
        this.setObject("Contact URL", contactUrl);
        this.setObject("Recieved As", new Byte(recievedAs));
        this.setObject("Name Of Seller", nameOfSeller);
        this.setObject("Description", description);
        this.setObject("Picture MIME Type", mimeType);
        this.setObject("Seller Logo", sellerLogo);
    }

    /**
     * Creates a new FrameBodyCOMR object.
     *
     * @param file DOCUMENT ME!
     *
     * @throws IOException DOCUMENT ME!
     * @throws InvalidTagException DOCUMENT ME!
     */
    public FrameBodyCOMR(java.io.RandomAccessFile file)
                  throws IOException, InvalidTagException {
        this.read(file);
    }

    /**
     * DOCUMENT ME!
     *
     * @return DOCUMENT ME!
     */
    public String getIdentifier() {
        String             str = "COMR";
        java.util.Iterator iterator = objectList.listIterator();

        while (iterator.hasNext()) {
            str += (((char) 0) + getOwner());
        }

        return str;
    }

    /**
     * DOCUMENT ME!
     *
     * @return DOCUMENT ME!
     */
    public String getOwner() {
        return (String) getObject("Owner");
    }

    /**
     * DOCUMENT ME!
     *
     * @param description DOCUMENT ME!
     */
    public void getOwner(String description) {
        setObject("Owner", description);
    }

    /**
     * DOCUMENT ME!
     */
    protected void setupObjectList() {
        objectList.add(new ObjectNumberHashMap(ObjectNumberHashMap.TEXT_ENCODING, 1));
        objectList.add(new ObjectStringNullTerminated("Price String"));
        objectList.add(new ObjectStringDate("Valid Until"));
        objectList.add(new ObjectStringNullTerminated("Contact URL"));
        objectList.add(new ObjectNumberHashMap(ObjectNumberHashMap.RECIEVED_AS, 1));
        objectList.add(new ObjectStringNullTerminated("Name Of Seller"));
        objectList.add(new ObjectStringNullTerminated("Description"));
        objectList.add(new ObjectStringNullTerminated("Picture MIME Type"));
        objectList.add(new ObjectByteArraySizeTerminated("Seller Logo"));
    }
}